package ssm.service;

import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ssm.dao.Teacher;
import ssm.dao.Track;
import ssm.dao.TrackCar;
import ssm.dao.YktCarinfo;
import ssm.model.TeacherMapper;
import ssm.model.TrackCarMapper;
import ssm.model.YktCarinfoMapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class YktCarinfoServiceImpl implements YktCarinfoService {

    @Autowired
    private YktCarinfoMapper yktCarinfoMapper;

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private TrackCarMapper trackCarMapper;

    public YktCarinfo getByCph(String cph) {
        System.out.println(cph);
        YktCarinfo carinfo = yktCarinfoMapper.getByCph(cph);
        System.out.println(carinfo);
        if (carinfo != null) {
            Teacher teacher = teacherMapper.getByGh(carinfo.getGh());
            carinfo.setOwnerinfo(teacher);
        }
        return carinfo;
    }

    public List<TrackCar> getByCphOrGh(String jid) {

        List<TrackCar> trackCars=new ArrayList<TrackCar>();
        List<String>cphms=yktCarinfoMapper.selectCphByJid(jid);
        if(cphms==null){
            return null;
        }
        for(String cphm:cphms){
            TrackCar trackCar=trackCarMapper.searchCar(cphm);
            if(trackCar!=null){
                trackCars.add(trackCar);
            }else{
                TrackCar car=new TrackCar();
                    car.setCphm(cphm);
                    car.setCllx("未知");
                    car.setClpp("未知");
                    car.setClys("未知");
                    car.setCplx("未知");
                    car.setCpys("未知");
                trackCars.add(car);
            }
        }
        return trackCars;

    }

}
